package com.hlw.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hlw.dao.MenuMapper;
import com.hlw.entity.Menu;
import com.hlw.service.IMenuService;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author Mht
 * @since 2020-05-02
 */
@Service
public class MenuServiceImpl implements IMenuService  {

	@Resource
	private MenuMapper mapper;
	@Override
	public Map<String, Object> findMenu() {
		  Map<String,Object> data = new HashMap<>();
	        //按照pid获取到根目录进行存储对应的子目录
	        List<Menu> navId = mapper.getmenuByPid();
	        for(Menu nav : navId){
	            List<Menu> navigationListByPId = mapper.getmenuListByPId(nav.getId());
	            nav.setChildrens(navigationListByPId);
	        }
	        data.put("menu",navId);
	        return data;
	 
	    }
	@Override
	public List<Menu> findAll() {
		
		return mapper.getMenus();
	}
	@Override
	public Menu findMenuById(String id) {
		// TODO Auto-generated method stub
		return mapper.selectById(id);
	}
	@Override
	public Integer delById(Integer id) {
		// TODO Auto-generated method stub
		return mapper.deletePerByRid(id);
	}
	@Override
	public List<Menu> findPerByRid(Integer rid) {
		// TODO Auto-generated method stub
		return mapper.findPermissionByRoleId(rid);
	}
	@Override
	public Integer addPerByRid(Integer rid, Integer mid) {
		// TODO Auto-generated method stub
		return mapper.inserPerByRid(rid, mid);
	}

}
